package com.lc.yygh.hosp.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.yygh.common.exception.YyghException;
import com.lc.yygh.common.result.ResultStatus;
import com.lc.yygh.hosp.mapper.HospitalSetMapper;
import com.lc.yygh.hosp.service.HospitalSetService;
import com.lc.yygh.model.hosp.HospitalSet;
import com.lc.yygh.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
/*要用mybatis-plus的IService接口，在service的实现类必须继承ServiceImpl。才能使用IService的方法,有很多方法实际上也是调用了BaseMapper的方法，所以之前的都是直接
* 调BaseMapper的方法的方法,之前用了BaseMapper，mapper层就不用写了，现在加上IService，service层也不用写了更简化了*/
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {

    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("sign_key","status").eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(queryWrapper);
        if (hospitalSet==null){
            throw new YyghException(ResultStatus.HOSPITAL_OPEN);
        }
        if (hospitalSet.getStatus().intValue()==0){
            throw new YyghException(ResultStatus.HOSPITAL_LOCK);
        }
        return hospitalSet.getSignKey();
    }

    //获取医院签名信息
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if(null == hospitalSet) {
            throw new YyghException(ResultStatus.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
